<!DOCTYPE html>
<html lang="zh-cn">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		 
			
  
    <meta name="twitter:card" content="summary"/>
    
      <meta name="twitter:image" content="https://www.samrainhan.com/images/avatar.png" />
    
  
  
  <meta name="twitter:title" content="Puma&#43;Nginx&#43;Mariadb&#43;Redmine"/>
  <meta name="twitter:description" content="以下均在Ubuntu 1404.2 LTS 上运行过。 redmine目录放在/home/redmine下。 1. Ruby install 基础库 sudo apt-get install git autoconf bison curl build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev install rbenv mkdir /home/redmine &amp;&amp;"/>
  
  
  
  
    <meta name="twitter:creator" content="@韩雨"/>
  



		
		<meta name="author" content="韩雨">
		<meta name="description" content="学习 &amp;nbsp;&amp;bull;&amp;nbsp; 生活">
		<meta name="generator" content="Hugo 0.52" />
		<title>Puma&#43;Nginx&#43;Mariadb&#43;Redmine &middot; sam的小窝</title>
		<link rel="shortcut icon" href="https://www.samrainhan.com/images/favicon.ico">
		<link rel="stylesheet" href="https://www.samrainhan.com/css/style.css">
		<link rel="stylesheet" href="https://www.samrainhan.com/css/highlight.css">

		
		<link rel="stylesheet" href="https://www.samrainhan.com/css/font-awesome.min.css">
		

		
		<link href="https://www.samrainhan.com/index.xml" rel="alternate" type="application/rss+xml" title="sam的小窝" />
		

		
	</head>

    <body>
       <nav class="main-nav">
	
	
		<a href='https://www.samrainhan.com/'> <span class="arrow">←</span>Home</a>
	
	<a href='https://www.samrainhan.com/posts'>Archive</a>
	<a href='https://www.samrainhan.com/tags'>Tags</a>
	<a href='https://www.samrainhan.com/about'>About</a>

	

	
	<a class="cta" href="https://www.samrainhan.com/index.xml">Subscribe</a>
	
</nav>


        <section id="wrapper" class="post">
            <article>
                <header>
                    <h1>
                        Puma&#43;Nginx&#43;Mariadb&#43;Redmine
                    </h1>
                    <h2 class="headline">
                    Jun 24, 2015 00:00
                    · 1490 words
                    · 3 minute read
                      <span class="tags">
                      
                      
                          
                              <a href="https://www.samrainhan.com/tags/redmine">Redmine</a>
                          
                              <a href="https://www.samrainhan.com/tags/nginx">Nginx</a>
                          
                              <a href="https://www.samrainhan.com/tags/puma">Puma</a>
                          
                      
                      
                      </span>
                    </h2>
                </header>
                
                  
                    <div id="toc">
                      <nav id="TableOfContents">
<ul>
<li>
<ul>
<li><a href="#1-ruby">1. Ruby</a>
<ul>
<li><a href="#install-基础库">install 基础库</a></li>
<li><a href="#install-rbenv">install rbenv</a></li>
<li><a href="#install-ruby">install Ruby</a></li>
<li><a href="#check-ruby">check Ruby</a></li>
</ul></li>
<li><a href="#2-mariadb">2. Mariadb</a>
<ul>
<li><a href="#基础库">基础库</a></li>
<li><a href="#配置数据库">配置数据库</a></li>
</ul></li>
<li><a href="#3-redmine">3. Redmine</a>
<ul>
<li><a href="#下载代码">下载代码</a></li>
<li><a href="#修改gemfile文件">修改Gemfile文件</a></li>
<li><a href="#安装ruby组件">安装ruby组件</a></li>
<li><a href="#创建redmine基础数据">创建redmine基础数据</a></li>
<li><a href="#测试">测试</a></li>
</ul></li>
<li><a href="#4-puma">4. Puma</a>
<ul>
<li><a href="#install-puma">install puma</a></li>
<li><a href="#创建服务并设置为自动启动">创建服务并设置为自动启动</a></li>
</ul></li>
<li><a href="#5-nginx">5. Nginx</a>
<ul>
<li><a href="#下载源码">下载源码</a></li>
<li><a href="#设置编译选项">设置编译选项</a></li>
<li><a href="#配置openresty-puma">配置openresty+puma</a></li>
<li><a href="#运行openresty">运行openresty</a></li>
</ul></li>
<li><a href="#6-更新ruby组件并重启所有服务">6. 更新ruby组件并重启所有服务</a></li>
<li><a href="#7-附录">7. 附录</a>
<ul>
<li><a href="#启动redmine自带服务-便于查错时确定问题源">启动redmine自带服务，便于查错时确定问题源</a></li>
<li><a href="#恢复样式定制">恢复样式定制</a></li>
</ul></li>
</ul></li>
</ul>
</nav>
                    </div>
                  
                
                <section id="post-body">
                    

<blockquote>
<p>以下均在Ubuntu 1404.2 LTS 上运行过。
redmine目录放在<code>/home/redmine</code>下。</p>
</blockquote>

<h2 id="1-ruby">1. Ruby</h2>

<h3 id="install-基础库">install 基础库</h3>

<pre><code>sudo apt-get install git autoconf bison curl build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
</code></pre>

<h3 id="install-rbenv">install rbenv</h3>

<pre><code>mkdir /home/redmine &amp;&amp; cd /home/redmine
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

## 把rbenv加到shell的path中，然后重启shell
echo 'export PATH=&quot;/home/redmine/.rbenv/bin:$PATH&quot;' &gt;&gt; ~/.bashrc
echo 'eval &quot;$(rbenv init -)&quot;' &gt;&gt; ~/.bashrc
exec $SHELL -l

## 检查rbenv是否ok
type rbenv
</code></pre>

<h3 id="install-ruby">install Ruby</h3>

<pre><code>## 看当前能安装的ruby版本
## 如果报没有install命令，可以查看下目录执行 .rbenv/plugins/ruby-build/install.sh安装
rbenv install -l

## 安装当前最新的稳定版本
## 比如2015-1-4时是2.2.0,但是由于后面使用redmine时有些插件报错，所以降级到2.1.5。编译超级慢，下载源码时有时会因为GFW无法下载，我后来用了土方法，重新启动。
rbenv install 2.1.5

## 设置ruby全局版本为这个
rbenv global 2.1.5
</code></pre>

<h3 id="check-ruby">check Ruby</h3>

<pre><code>## 确认下当前ruby版本号是否和设置的全局版本一致
ruby -v

## 如果不一致，那么执行以下2行代码
rbenv rehash
rbenv global 2.1.5
</code></pre>

<h2 id="2-mariadb">2. Mariadb</h2>

<h3 id="基础库">基础库</h3>

<p>安装过程中会要求输入MariaDB的root用户密码</p>

<pre><code>sudo apt-get install mariadb-server libmariadbclient-dev ImageMagick libmagickwand-dev
</code></pre>

<h3 id="配置数据库">配置数据库</h3>

<pre><code>## 登录Mariadb
mysql -uroot -p

## 创建新库
CREATE DATABASE redm4coprize CHARACTER SET utf8;

## 创建数据库用户
CREATE USER 'user4coprize'@'localhost' IDENTIFIED BY '7ujm*IK&lt;';

## 赋予它权限
GRANT ALL PRIVILEGES ON redm4coprize.* TO 'user4coprize'@'localhost';

## 离开数据库
\q
</code></pre>

<h2 id="3-redmine">3. Redmine</h2>

<h3 id="下载代码">下载代码</h3>

<p>比如2014-12-20时是2.6.0，这个可以到<a href="http://www.redmine.org/projects/redmine/wiki/Download#Stable-releases">redmine官网</a>上看到.</p>

<pre><code>## 安装2.5.2版本
wget -c http://www.redmine.org/releases/redmine-2.5.2.tar.gz
tar -xf *.tar.gz &amp;&amp; cd redm*
## 创建文件夹
mkdir -p tmp/pids tmp/sockets public/plugin_assets
## 修改文件夹权限
chmod -R 755 files log tmp public/plugin_assets
</code></pre>

<h3 id="修改gemfile文件">修改Gemfile文件</h3>

<p>把第一行改为</p>

<blockquote>
<p>source &lsquo;<a href="https://ruby.taobao.org'">https://ruby.taobao.org'</a></p>
</blockquote>

<pre><code>vi ~/redmine*/Gemfile
</code></pre>

<h3 id="安装ruby组件">安装ruby组件</h3>

<pre><code>## 换gem源
gem sources --remove https://rubygems.org/
gem source -a https://ruby.taobao.org
gem source -c

## 安装bundler
gem install bundler
gem update
rbenv rehash

## 注意一定要先进入redmine的目录中
cd /home/red*/red*
bundle install --without development test postgresql sqlite

</code></pre>

<h3 id="创建redmine基础数据">创建redmine基础数据</h3>

<pre><code>bundle exec rake generate_secret_token
bundle exec rake db:migrate RAILS_ENV=production 
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
bundle exec rake redmine:load_default_data RAILS_ENV=production REDMINE_LANG=zh
</code></pre>

<h3 id="测试">测试</h3>

<p>访问<a href="http://localhost:3000">http://localhost:3000</a>,用户名和密码为admin/admin</p>

<pre><code>ruby script/rails server webrick -e production
</code></pre>

<h2 id="4-puma">4. Puma</h2>

<h3 id="install-puma">install puma</h3>

<pre><code>## 下载puma配置
curl -Lo ~/redmine*/config/puma.rb https://gist.githubusercontent.com/samrain/4c92673990edfe5a215e/raw/7313da9e309de0def3e40e75913bc0bfbe7d1fa3/puma.rb

## 在Gemfile中添加puma配置项
echo 'gem &quot;puma&quot;' &gt;&gt; Gemfile

## 安装puma
gem update
rbenv rehash
cd /home/red*/red*
bundle install --without development test postgresql sqlite
rake generate_secret_token
RAILS_ENV=production rake db:migrate
</code></pre>

<h3 id="创建服务并设置为自动启动">创建服务并设置为自动启动</h3>

<pre><code>## 创建启动脚本
sudo curl --output /etc/init.d/redm4coprize https://gist.githubusercontent.com/samrain/c5ea2900b1ee1ce3917d/raw/4534209303e63c452eebe56ab77f628ffaef479e/redmine%20service%204%20coprize
##加上执行权限
sudo chmod +x /etc/init.d/redm4coprize
## 启动时一起启动
sudo update-rc.d redm4coprize defaults 21
## 启动服务
sudo service redm4coprize start
</code></pre>

<h2 id="5-nginx">5. Nginx</h2>

<blockquote>
<p>支持下国人开源作品，以下用OpenResty来代替官方Nginx</p>
</blockquote>

<h3 id="下载源码">下载源码</h3>

<p><a href="http://openresty.org/download">下载页面在此</a>，请根据需要下载release版本。</p>

<pre><code>wget http://openresty.org/download/ngx_openresty-1.7.7.1.tar.gz
tar xzvf ngx_open*.gz &amp;&amp; cd ngx_open*
</code></pre>

<p>###编译前准备</p>

<pre><code>sudo apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl make
</code></pre>

<h3 id="设置编译选项">设置编译选项</h3>

<pre><code>./configure
make
sudo make install
</code></pre>

<h3 id="配置openresty-puma">配置openresty+puma</h3>

<pre><code>sudo curl -Lo /usr/local/openresty/nginx/conf/nginx.conf https://gist.githubusercontent.com/samrain/53059ff49c6a8d184170/raw/c8b68e8afddefe85bb508b3fa04f991c48368e36/openresty-conf-4-puma
</code></pre>

<h3 id="运行openresty">运行openresty</h3>

<pre><code>sudo /usr/local/openresty/nginx/sbin/nginx start
</code></pre>

<blockquote>
<p>重启openresty <code>sudo /usr/local/openresty/nginx/sbin/nginx -s reload</code></p>
</blockquote>

<h2 id="6-更新ruby组件并重启所有服务">6. 更新ruby组件并重启所有服务</h2>

<pre><code>cd %redmin安装目录%
gem update
rbenv rehash
bundle update
bundle install --without development test RAILS_ENV=production
bundle exec rake generate_secret_token
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake redmine:load_default_data RAILS_ENV=production REDMINE_LANG=zh
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
bundle exec rake tmp:cache:clear
bundle exec rake tmp:sessions:clear
bundle exec rake assets:precompile RAILS_ENV=production 

sudo service redm4coprize restart

sudo /usr/local/openresty/nginx/sbin/nginx -s reload
</code></pre>

<h2 id="7-附录">7. 附录</h2>

<h3 id="启动redmine自带服务-便于查错时确定问题源">启动redmine自带服务，便于查错时确定问题源</h3>

<pre><code>cd %redmin安装目录%
gem update
rbenv rehash
bundle update
bundle install --without development test RAILS_ENV=production
bundle exec rake generate_secret_token
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake redmine:load_default_data RAILS_ENV=production REDMINE_LANG=zh
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
bundle exec rake tmp:cache:clear
bundle exec rake tmp:sessions:clear
bundle exec rake assets:precompile RAILS_ENV=production 
ruby script/rails server webrick -e production
</code></pre>

<p>访问<a href="http://localhost:3000">http://localhost:3000</a>,用户名和密码为admin/admin</p>

<h3 id="恢复样式定制">恢复样式定制</h3>

<p>复制样式文件夹(比如<code>newmine-master</code>)到<code>%redmine安装目录%/public/themes/</code>，然后在redmine的管理界面里选择这个样式。</p>

<p>###增加邮件转发配置</p>

<p>修改<code>%redmine安装目录%/config/configuration.yml</code>,增加mail的配置</p>

<p>###备份</p>

<pre><code>mysqldump --default-character-set=utf8 -r %备份文件名及全路径% --databases %redmine数据库% -u %用户名% -p
</code></pre>

<p>###导入数据</p>

<blockquote>
<p>注意：不要用root登录数据库，一定要用数据库账号，否则导入时会新增一个数据库。</p>
</blockquote>

<pre><code>source %备份文件名及全路径%
</code></pre>

                </section>
            </article>

            
                <a class="twitter" href="https://twitter.com/intent/tweet?text=https%3a%2f%2fwww.samrainhan.com%2fposts%2f2015-06-24-puma-nginx-mariadb-redmine%2f - Puma%2bNginx%2bMariadb%2bRedmine "><span class="icon-twitter"> tweet</span></a>

<a class="facebook" href="#" onclick="
    window.open(
      'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href),
      'facebook-share-dialog',
      'width=626,height=436');
    return false;"><span class="icon-facebook-rect"> Share</span>
</a>

            

            
                <div id="disqus_thread"></div>
<script type="text/javascript">
    var disqus_shortname = 'samrainblogbygithub'; 

     
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>

            

            
                <ul id="post-list" class="archive readmore">
    <h3>Read more</h3>

    
    
    
        <li>
            <a href="/posts/2019-04-26-c9-move-to-aws-c9/">Cloud9 Move to Aws C9<aside class="dates">Apr 26 2019</aside></a>
        </li>
    
        <li>
            <a href="/posts/2019-02-16-why-build-blog-with-cloud9/">2019 02 16 Why Build Blog With Cloud9<aside class="dates">Feb 16 2019</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-sports-stretching-best-practices/">运动拉伸最佳实践<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-add-2-files-to-tempdb-for-caching/">给tempdb加2个文件做缓存<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-look-for-sql-server-tables-without-a-clustered-index/">如何找到没有聚集索引的表<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-the-continuous-delivery-maturity-model/">持续实施成熟度模型<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-map-of-continuous-delivery/">持续发布的各个阶段<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-how-dropbox-securely-stores-your-passwords/">Dropbox的用户密码加密机制<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-code-inspection-tool-for-net/">NET代码检查工具<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-how-to-make-unique-id/">怎样生成唯一ID<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
</ul>

            

            <footer id="footer">
    
        <div id="social">

	
	
    <a class="symbol" href="">
        <i class="fa fa-facebook-square"></i>
    </a>
    
    <a class="symbol" href="https://github.com/samrain">
        <i class="fa fa-github-square"></i>
    </a>
    
    <a class="symbol" href="">
        <i class="fa fa-twitter-square"></i>
    </a>
    


</div>

    
    <p class="small">
    
       © Copyright 2019 <i class="fa fa-heart" aria-hidden="true"></i> 韩雨
    
    </p>
    <p class="small">
        Powered by <a href="http://www.gohugo.io/">Hugo</a> Theme By <a href="https://github.com/nodejh/hugo-theme-cactus-plus">nodejh</a>
    </p>
</footer>

        </section>

        <script src="https://www.samrainhan.com/js/jquery-3.3.1.min.js"></script>
<script src="https://www.samrainhan.com/js/main.js"></script>
<script src="https://www.samrainhan.com/js/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>




  
<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
	})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
	ga('create', 'UA-37708730-1', 'auto');
	
	ga('send', 'pageview');
}
</script>





    </body>
</html>
